package com.liangsong.designpattern.factory;

import com.liangsong.designpattern.factory.common.Baozi;
import com.liangsong.designpattern.factory.common.PorkBaozi;
import com.liangsong.designpattern.factory.common.SuancaiBaozi;

/**
 * @author liangsong
 * @version v1.0 2025/1/9
 * 相比传统模式，从类图上就可以看出来，在sale和baozi中间又加了一层。
 * 通过封装SimpleFactory这个类，我们将sale和baozi进行了解耦合。
 * */
public class SimpleFactory {
    public static Baozi createBaozi(String type){
        return switch (type) {
            case "suancai" -> new SuancaiBaozi();
            case "pork" -> new PorkBaozi();
            default -> throw new IllegalArgumentException("没有这种包子");
        };
    }
}
